var thinkjs = require('thinkjs');
var path = require('path');
var childProcess = require('child_process');

var rootPath = path.dirname(__dirname);
var env_type="development";

var instance = new thinkjs({
  APP_PATH: rootPath + path.sep + 'app',
  RUNTIME_PATH: rootPath + path.sep + 'runtime',
  ROOT_PATH: rootPath,
  RESOURCE_PATH: __dirname,
  env: env_type
});

// Build code from src to app directory.
instance.compile({
  log: true
});
//cross-env方式可以兼容各种系统环境:windows是用set NODE_ENV=production 而linux是export NODE_ENV=production;
var p = childProcess.exec(`cross-env NODE_ENV=${env_type} webpack --config webpack.config.js --optimize-minimize -p`);
p.stdout.pipe(process.stdout);

var p1 = childProcess.exec(`cross-env NODE_ENV=${env_type} npm run compile`);
p1.stdout.pipe(process.stdout);

instance.run();
